/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.testis.gui.mvc.view.testbed;

import org.testis.gui.mvc.controller.TestBedControllerList;
import org.testis.gui.mvc.view.AbstractViewPanel;
import org.testis.gui.mvc.controller.testbed.*;
import org.testis.orm.testbed.refined.DeviceFirmwareRefined;
import org.testis.orm.testbed.refined.DeviceGroupDetailRefined;
import org.testis.orm.testbed.refined.DeviceGroupRefined;
import org.testis.orm.testbed.refined.DirectSerialConfigRefined;
import org.testis.orm.testbed.refined.DutRefined;
import org.testis.orm.testbed.refined.NetworkAdapterRefined;
import org.testis.orm.testbed.refined.SerialConnectionRefined;
import org.testis.orm.testbed.refined.TestBedItem;
import org.testis.orm.testbed.refined.TestPcRefined;
import org.testis.utils.tree.TbedMutableTreeNode;
import java.awt.event.ActionEvent;
import java.awt.event.MouseEvent;
import java.beans.PropertyChangeEvent;
import java.util.Iterator;
import java.util.List;
import javax.swing.JPopupMenu;

/**
 *
 * @author selcuk
 */
public class TbedPopupMenu extends JPopupMenu implements AbstractViewPanel {

    private boolean m_visible = false;
    private DeviceDefinitionController m_deviceDefinitionController;
    private DeviceFirmwareController m_firmwareController;
    private TbedTreeController m_treeController;
    private DeviceGroupDetailController m_deviceGroupDetailController;

    public TbedPopupMenu() {
        super();
        initComponents();

        m_treeController = TestBedControllerList.newInstance().getTbedTreeController();
        m_deviceDefinitionController = TestBedControllerList.newInstance().getDeviceDefinitionController();
        m_firmwareController = TestBedControllerList.newInstance().getDeviceFirmwareController();
        m_deviceGroupDetailController = TestBedControllerList.newInstance().getDeviceGroupDetailController();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">
    private void initComponents() {
        popupMenu = new javax.swing.JPopupMenu();
        addDeviceMenuItem = new javax.swing.JMenuItem();
        editDeviceMenuItem = new javax.swing.JMenuItem();
        deleteDeviceMenuItem = new javax.swing.JMenuItem();
        addFirmwareMenuItem = new javax.swing.JMenuItem();
        editFirmwareMenuItem = new javax.swing.JMenuItem();
        deleteFirmwareMenuItem = new javax.swing.JMenuItem();
        addTestPcMenuItem = new javax.swing.JMenuItem();
        editTestPcMenuItem = new javax.swing.JMenuItem();
        deleteTestPcMenuItem = new javax.swing.JMenuItem();
        addDeviceGroupMenuItem = new javax.swing.JMenuItem();
        editDeviceGroupMenuItem = new javax.swing.JMenuItem();
        deleteDeviceGroupMenuItem = new javax.swing.JMenuItem();
        addDeviceGroupDetailMenuItem = new javax.swing.JMenuItem();
        editDeviceGroupDetailMenuItem = new javax.swing.JMenuItem();
        deleteDeviceGroupDetailMenuItem = new javax.swing.JMenuItem();
        addDutMenuItem = new javax.swing.JMenuItem();
        editDutMenuItem = new javax.swing.JMenuItem();
        deleteDutMenuItem = new javax.swing.JMenuItem();
        addAdapterMenuItem = new javax.swing.JMenuItem();
        editAdapterMenuItem = new javax.swing.JMenuItem();
        deleteAdapterMenuItem = new javax.swing.JMenuItem();
        addSerialConnMenuItem = new javax.swing.JMenuItem();
        editSerialConnMenuItem = new javax.swing.JMenuItem();
        deleteSerialConnMenuItem = new javax.swing.JMenuItem();
        addDirectSerialMenuItem = new javax.swing.JMenuItem();
        editDirectSerialMenuItem = new javax.swing.JMenuItem();
        deleteDirectSerialMenuItem = new javax.swing.JMenuItem();
        addNetworkSerialMenuItem = new javax.swing.JMenuItem();
        editNetworkSerialMenuItem = new javax.swing.JMenuItem();
        deleteNetworkSerialMenuItem = new javax.swing.JMenuItem();
        addDeviceMenuItem.setText("New Device");
        addDeviceMenuItem.setVisible(false);
        addDeviceMenuItem.addActionListener(new java.awt.event.ActionListener() {

            public void actionPerformed(java.awt.event.ActionEvent evt) {
                addDeviceMenuItemActionPerformed(evt);
            }
        });
        popupMenu.add(addDeviceMenuItem);

        editDeviceMenuItem.setText("Edit");
        editDeviceMenuItem.setVisible(false);
        editDeviceMenuItem.addActionListener(new java.awt.event.ActionListener() {

            public void actionPerformed(java.awt.event.ActionEvent evt) {
                editDeviceMenuItemActionPerformed(evt);
            }
        });
        popupMenu.add(editDeviceMenuItem);

        deleteDeviceMenuItem.setText("Delete");
        deleteDeviceMenuItem.setVisible(false);
        deleteDeviceMenuItem.addActionListener(new java.awt.event.ActionListener() {

            public void actionPerformed(java.awt.event.ActionEvent evt) {
                deleteDeviceMenuItemActionPerformed(evt);
            }
        });
        popupMenu.add(deleteDeviceMenuItem);

        addFirmwareMenuItem.setText("New Firmware");
        addFirmwareMenuItem.setVisible(false);
        addFirmwareMenuItem.addActionListener(new java.awt.event.ActionListener() {

            public void actionPerformed(java.awt.event.ActionEvent evt) {
                addFirmwareMenuItemActionPerformed(evt);
            }
        });
        popupMenu.add(addFirmwareMenuItem);

        editFirmwareMenuItem.setText("Edit Firmware");
        editFirmwareMenuItem.setVisible(false);
        editFirmwareMenuItem.addActionListener(new java.awt.event.ActionListener() {

            public void actionPerformed(java.awt.event.ActionEvent evt) {
                editFirmwareMenuItemActionPerformed(evt);
            }
        });
        popupMenu.add(editFirmwareMenuItem);

        deleteFirmwareMenuItem.setText("Delete Firmware");
        deleteFirmwareMenuItem.setVisible(false);
        deleteFirmwareMenuItem.addActionListener(new java.awt.event.ActionListener() {

            public void actionPerformed(java.awt.event.ActionEvent evt) {
                deleteFirmwareMenuItemActionPerformed(evt);
            }
        });
        popupMenu.add(deleteFirmwareMenuItem);

        addTestPcMenuItem.setText("New TestPC");
        addTestPcMenuItem.setVisible(false);
        addTestPcMenuItem.addActionListener(new java.awt.event.ActionListener() {

            public void actionPerformed(java.awt.event.ActionEvent evt) {
                addTestPcMenuItemActionPerformed(evt);
            }
        });
        popupMenu.add(addTestPcMenuItem);

        editTestPcMenuItem.setText("Edit TestPC");
        editTestPcMenuItem.setVisible(false);
        editTestPcMenuItem.addActionListener(new java.awt.event.ActionListener() {

            public void actionPerformed(java.awt.event.ActionEvent evt) {
                editTestPcMenuItemActionPerformed(evt);
            }
        });
        popupMenu.add(editTestPcMenuItem);

        deleteTestPcMenuItem.setText("Delete TestPC");
        deleteTestPcMenuItem.setVisible(false);
        deleteTestPcMenuItem.addActionListener(new java.awt.event.ActionListener() {

            public void actionPerformed(java.awt.event.ActionEvent evt) {
                deleteTestPcMenuItemActionPerformed(evt);
            }
        });
        popupMenu.add(deleteTestPcMenuItem);

        addDeviceGroupMenuItem.setText("New DeviceGroup");
        addDeviceGroupMenuItem.setVisible(false);
        addDeviceGroupMenuItem.addActionListener(new java.awt.event.ActionListener() {

            public void actionPerformed(java.awt.event.ActionEvent evt) {
                addDeviceGroupMenuItemActionPerformed(evt);
            }
        });
        popupMenu.add(addDeviceGroupMenuItem);

        editDeviceGroupMenuItem.setText("Edit DeviceGroup");
        editDeviceGroupMenuItem.setVisible(false);
        editDeviceGroupMenuItem.addActionListener(new java.awt.event.ActionListener() {

            public void actionPerformed(java.awt.event.ActionEvent evt) {
                editDeviceGroupMenuItemActionPerformed(evt);
            }
        });
        popupMenu.add(editDeviceGroupMenuItem);

        deleteDeviceGroupMenuItem.setText("Delete DeviceGroup");
        deleteDeviceGroupMenuItem.setVisible(false);
        deleteDeviceGroupMenuItem.addActionListener(new java.awt.event.ActionListener() {

            public void actionPerformed(java.awt.event.ActionEvent evt) {
                deleteDeviceGroupMenuItemActionPerformed(evt);
            }
        });
        popupMenu.add(deleteDeviceGroupMenuItem);

        addDeviceGroupDetailMenuItem.setText("New Detail");
        addDeviceGroupDetailMenuItem.setVisible(false);
        addDeviceGroupDetailMenuItem.addActionListener(new java.awt.event.ActionListener() {

            public void actionPerformed(java.awt.event.ActionEvent evt) {
                addDeviceGroupDetailMenuItemActionPerformed(evt);
            }
        });
        popupMenu.add(addDeviceGroupDetailMenuItem);

        editDeviceGroupDetailMenuItem.setText("Edit Detail");
        editDeviceGroupDetailMenuItem.setVisible(false);
        editDeviceGroupDetailMenuItem.addActionListener(new java.awt.event.ActionListener() {

            public void actionPerformed(java.awt.event.ActionEvent evt) {
                editDeviceGroupDetailMenuItemActionPerformed(evt);
            }
        });
        popupMenu.add(editDeviceGroupDetailMenuItem);

        deleteDeviceGroupDetailMenuItem.setText("Delete Detail");
        deleteDeviceGroupDetailMenuItem.setVisible(false);
        deleteDeviceGroupDetailMenuItem.addActionListener(new java.awt.event.ActionListener() {

            public void actionPerformed(java.awt.event.ActionEvent evt) {
                deleteDeviceGroupDetailMenuItemActionPerformed(evt);
            }
        });
        popupMenu.add(deleteDeviceGroupDetailMenuItem);

        addDutMenuItem.setText("New Dut");
        addDutMenuItem.setVisible(false);
        addDutMenuItem.addActionListener(new java.awt.event.ActionListener() {

            @Override
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                addDutMenuItemActionPerformed(evt);
            }
        });
        popupMenu.add(addDutMenuItem);

        editDutMenuItem.setText("Edit");
        editDutMenuItem.setVisible(false);
        editDutMenuItem.addActionListener(new java.awt.event.ActionListener() {

            @Override
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                editDutMenuItemActionPerformed(evt);
            }
        });
        popupMenu.add(editDutMenuItem);

        deleteDutMenuItem.setText("Delete");
        deleteDutMenuItem.setVisible(false);
        deleteDutMenuItem.addActionListener(new java.awt.event.ActionListener() {

            @Override
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                deleteDutMenuItemActionPerformed(evt);
            }
        });
        popupMenu.add(deleteDutMenuItem);

        addAdapterMenuItem.setText("New Adapter");
        addAdapterMenuItem.setVisible(false);
        addAdapterMenuItem.addActionListener(new java.awt.event.ActionListener() {

            @Override
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                addAdapterMenuItemActionPerformed(evt);
            }
        });
        popupMenu.add(addAdapterMenuItem);

        editAdapterMenuItem.setText("Edit");
        editAdapterMenuItem.setVisible(false);
        editAdapterMenuItem.addActionListener(new java.awt.event.ActionListener() {

            @Override
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                editAdapterMenuItemActionPerformed(evt);
            }
        });
        popupMenu.add(editAdapterMenuItem);


        deleteAdapterMenuItem.setText("Delete");
        deleteAdapterMenuItem.setVisible(false);
        deleteAdapterMenuItem.addActionListener(new java.awt.event.ActionListener() {

            @Override
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                deleteAdapterMenuItemActionPerformed(evt);
            }
        });
        popupMenu.add(deleteAdapterMenuItem);

        addDirectSerialMenuItem.setText("New Direct Serial");
        addDirectSerialMenuItem.setVisible(false);
        addDirectSerialMenuItem.addActionListener(new java.awt.event.ActionListener() {

            @Override
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                addDirectSerialMenuItemActionPerformed(evt);
            }
        });
        popupMenu.add(addDirectSerialMenuItem);

        editDirectSerialMenuItem.setText("Edit");
        editDirectSerialMenuItem.setVisible(false);
        editDirectSerialMenuItem.addActionListener(new java.awt.event.ActionListener() {

            @Override
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                editDirectSerialMenuItemActionPerformed(evt);
            }
        });
        popupMenu.add(editDirectSerialMenuItem);

        deleteDirectSerialMenuItem.setText("Delete");
        deleteDirectSerialMenuItem.setVisible(false);
        deleteDirectSerialMenuItem.addActionListener(new java.awt.event.ActionListener() {

            @Override
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                deleteDirectSerialMenuItemActionPerformed(evt);
            }
        });
        popupMenu.add(deleteDirectSerialMenuItem);

        addNetworkSerialMenuItem.setText("New Network Serial");
        addNetworkSerialMenuItem.setVisible(false);
        addNetworkSerialMenuItem.addActionListener(new java.awt.event.ActionListener() {

            @Override
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                addNetworkSerialMenuItemActionPerformed(evt);
            }
        });
        popupMenu.add(addNetworkSerialMenuItem);

        editNetworkSerialMenuItem.setText("Edit");
        editNetworkSerialMenuItem.setVisible(false);
        editNetworkSerialMenuItem.addActionListener(new java.awt.event.ActionListener() {

            @Override
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                editNetworkSerialMenuItemActionPerformed(evt);
            }
        });
        popupMenu.add(editNetworkSerialMenuItem);

        deleteNetworkSerialMenuItem.setText("Delete");
        deleteNetworkSerialMenuItem.setVisible(false);
        deleteNetworkSerialMenuItem.addActionListener(new java.awt.event.ActionListener() {

            @Override
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                deleteNetworkSerialMenuItemActionPerformed(evt);
            }
        });
        popupMenu.add(deleteNetworkSerialMenuItem);

        addSerialConnMenuItem.setText("New Serial Config");
        addSerialConnMenuItem.setVisible(false);
        addSerialConnMenuItem.addActionListener(new java.awt.event.ActionListener() {

            public void actionPerformed(java.awt.event.ActionEvent evt) {
                addSerialConnMenuItemActionPerformed(evt);
            }
        });
        popupMenu.add(addSerialConnMenuItem);

        editSerialConnMenuItem.setText("Edit");
        editSerialConnMenuItem.setVisible(false);
        editSerialConnMenuItem.addActionListener(new java.awt.event.ActionListener() {

            public void actionPerformed(java.awt.event.ActionEvent evt) {
                editSerialConnMenuItemActionPerformed(evt);
            }
        });
        popupMenu.add(editSerialConnMenuItem);

        deleteSerialConnMenuItem.setText("Delete");
        deleteSerialConnMenuItem.setVisible(false);
        deleteSerialConnMenuItem.addActionListener(new java.awt.event.ActionListener() {

            public void actionPerformed(java.awt.event.ActionEvent evt) {
                deleteSerialConnMenuItemActionPerformed(evt);
            }
        });
        popupMenu.add(deleteSerialConnMenuItem);


    }// </editor-fold>

    @Override
    public void modelPropertyChange(PropertyChangeEvent evt) {
        if (evt.getPropertyName().equals(TbedPopupController.OPEN_POPUP_MENU)) {
            MouseEvent e = (MouseEvent) evt.getNewValue();
            popupMenu.show(e.getComponent(), e.getX(), e.getY());
        } else if (evt.getPropertyName().equals(
                TbedPopupController.POPUP_MENU_ADD_DEVICE_VISIBILITY)) {
            Boolean val = (Boolean) evt.getNewValue();
            addDeviceMenuItem.setVisible(val);
        } else if (evt.getPropertyName().equals(
                TbedPopupController.POPUP_MENU_EDIT_DEVICE_VISIBILITY)) {
            Boolean val = (Boolean) evt.getNewValue();
            editDeviceMenuItem.setVisible(val);
        } else if (evt.getPropertyName().equals(
                TbedPopupController.POPUP_MENU_DELETE_DEVICE_VISIBILITY)) {
            Boolean val = (Boolean) evt.getNewValue();
            deleteDeviceMenuItem.setVisible(val);
        } else if (evt.getPropertyName().equals(
                TbedPopupController.POPUP_MENU_ADD_FW_VISIBILITY)) {
            Boolean val = (Boolean) evt.getNewValue();
            addFirmwareMenuItem.setVisible(val);
        } else if (evt.getPropertyName().equals(
                TbedPopupController.POPUP_MENU_EDIT_FW_VISIBILITY)) {
            Boolean val = (Boolean) evt.getNewValue();
            editFirmwareMenuItem.setVisible(val);
        } else if (evt.getPropertyName().equals(
                TbedPopupController.POPUP_MENU_DELETE_FW_VISIBILITY)) {
            Boolean val = (Boolean) evt.getNewValue();
            deleteFirmwareMenuItem.setVisible(val);
        } else if (evt.getPropertyName().equals(
                TbedPopupController.POPUP_MENU_ADD_TESTPC_VISIBILITY)) {
            Boolean val = (Boolean) evt.getNewValue();
            addTestPcMenuItem.setVisible(val);
        } else if (evt.getPropertyName().equals(
                TbedPopupController.POPUP_MENU_EDIT_TESTPC_VISIBILITY)) {
            Boolean val = (Boolean) evt.getNewValue();
            editTestPcMenuItem.setVisible(val);
        } else if (evt.getPropertyName().equals(
                TbedPopupController.POPUP_MENU_DELETE_TESTPC_VISIBILITY)) {
            Boolean val = (Boolean) evt.getNewValue();
            deleteTestPcMenuItem.setVisible(val);
        } else if (evt.getPropertyName().equals(
                TbedPopupController.POPUP_MENU_ADD_DEVICEGROUP_VISIBILITY)) {
            Boolean val = (Boolean) evt.getNewValue();
            addDeviceGroupMenuItem.setVisible(val);
        } else if (evt.getPropertyName().equals(
                TbedPopupController.POPUP_MENU_EDIT_DEVICEGROUP_VISIBILITY)) {
            Boolean val = (Boolean) evt.getNewValue();
            editDeviceGroupMenuItem.setVisible(val);
        } else if (evt.getPropertyName().equals(
                TbedPopupController.POPUP_MENU_DELETE_DEVICEGROUP_VISIBILITY)) {
            Boolean val = (Boolean) evt.getNewValue();
            deleteDeviceGroupMenuItem.setVisible(val);
        } else if (evt.getPropertyName().equals(
                TbedPopupController.POPUP_MENU_ADD_DEVICEGROUPDETAIL_VISIBILITY)) {
            Boolean val = (Boolean) evt.getNewValue();
            addDeviceGroupDetailMenuItem.setVisible(val);
        } else if (evt.getPropertyName().equals(
                TbedPopupController.POPUP_MENU_EDIT_DEVICEGROUPDETAIL_VISIBILITY)) {
            Boolean val = (Boolean) evt.getNewValue();
            editDeviceGroupDetailMenuItem.setVisible(val);
        } else if (evt.getPropertyName().equals(
                TbedPopupController.POPUP_MENU_DELETE_DEVICEGROUPDETAIL_VISIBILITY)) {
            Boolean val = (Boolean) evt.getNewValue();
            deleteDeviceGroupDetailMenuItem.setVisible(val);
        } else if (evt.getPropertyName().equals(
                TbedPopupController.POPUP_MENU_ADD_DUT_VISIBILITY)) {
            Boolean val = (Boolean) evt.getNewValue();
            addDutMenuItem.setVisible(val);
        } else if (evt.getPropertyName().equals(
                TbedPopupController.POPUP_MENU_EDIT_DUT_VISIBILITY)) {
            Boolean val = (Boolean) evt.getNewValue();
            editDutMenuItem.setVisible(val);
        } else if (evt.getPropertyName().equals(
                TbedPopupController.POPUP_MENU_DELETE_DUT_VISIBILITY)) {
            Boolean val = (Boolean) evt.getNewValue();
            deleteDutMenuItem.setVisible(val);
        } else if (evt.getPropertyName().equals(
                TbedPopupController.POPUP_MENU_ADD_NETWORKADAPTER_VISIBILITY)) {
            Boolean val = (Boolean) evt.getNewValue();
            addAdapterMenuItem.setVisible(val);
        } else if (evt.getPropertyName().equals(
                TbedPopupController.POPUP_MENU_EDIT_NETWORKADAPTER_VISIBILITY)) {
            Boolean val = (Boolean) evt.getNewValue();
            editAdapterMenuItem.setVisible(val);
        } else if (evt.getPropertyName().equals(
                TbedPopupController.POPUP_MENU_DELETE_NETWORKADAPTER_VISIBILITY)) {
            Boolean val = (Boolean) evt.getNewValue();
            deleteAdapterMenuItem.setVisible(val);
        } else if (evt.getPropertyName().equals(
                TbedPopupController.POPUP_MENU_ADD_SERIAL_VISIBILITY)) {
            Boolean val = (Boolean) evt.getNewValue();
            addSerialConnMenuItem.setVisible(val);
        } else if (evt.getPropertyName().equals(
                TbedPopupController.POPUP_MENU_EDIT_SERIAL_VISIBILITY)) {
            Boolean val = (Boolean) evt.getNewValue();
            editSerialConnMenuItem.setVisible(val);
        } else if (evt.getPropertyName().equals(
                TbedPopupController.POPUP_MENU_DELETE_SERIAL_VISIBILITY)) {
            Boolean val = (Boolean) evt.getNewValue();
            deleteSerialConnMenuItem.setVisible(val);
        } else if (evt.getPropertyName().equals(
                TbedPopupController.POPUP_MENU_ADD_DIRECTSERIAL_VISIBILITY)) {
            Boolean val = (Boolean) evt.getNewValue();
            addDirectSerialMenuItem.setVisible(val);
        } else if (evt.getPropertyName().equals(
                TbedPopupController.POPUP_MENU_EDIT_DIRECTSERIAL_VISIBILITY)) {
            Boolean val = (Boolean) evt.getNewValue();
            editDirectSerialMenuItem.setVisible(val);
        } else if (evt.getPropertyName().equals(
                TbedPopupController.POPUP_MENU_DELETE_DIRECTSERIAL_VISIBILITY)) {
            Boolean val = (Boolean) evt.getNewValue();
            deleteDirectSerialMenuItem.setVisible(val);
        } else if (evt.getPropertyName().equals(
                TbedPopupController.POPUP_MENU_ADD_NETWORKSERIAL_VISIBILITY)) {
            Boolean val = (Boolean) evt.getNewValue();
            addNetworkSerialMenuItem.setVisible(val);
        } else if (evt.getPropertyName().equals(
                TbedPopupController.POPUP_MENU_EDIT_NETWORKSERIAL_VISIBILITY)) {
            Boolean val = (Boolean) evt.getNewValue();
            editNetworkSerialMenuItem.setVisible(val);
        } else if (evt.getPropertyName().equals(
                TbedPopupController.POPUP_MENU_DELETE_NETWORKSERIAL_VISIBILITY)) {
            Boolean val = (Boolean) evt.getNewValue();
            deleteNetworkSerialMenuItem.setVisible(val);
        }
    }

    private void addDirectSerialMenuItemActionPerformed(ActionEvent evt) {
        TestBedControllerList.newInstance().getDirectSerialConfigController().operationNewConfig();
    }

    private void editDirectSerialMenuItemActionPerformed(ActionEvent evt) {
        TbedMutableTreeNode node = TestBedControllerList.newInstance().getTbedTreeController().getSelectedTreeNode();
        TestBedControllerList.newInstance().getDirectSerialConfigController().operationEditConfig(
                node);
        TestBedControllerList.newInstance().getTbedTreeController().operationRefreshTree();
    }

    private void deleteDirectSerialMenuItemActionPerformed(ActionEvent evt) {
        TestBedItem tbedItem = TestBedControllerList.newInstance().getTbedTreeController().getSelectedTestBedItem();
        if (tbedItem != null && tbedItem instanceof DirectSerialConfigRefined) {
            DirectSerialConfigRefined refined = (DirectSerialConfigRefined) tbedItem;
//            TestBedControllerList.newInstance().getDirectSerialConfigController().operationRemoveAdapter(
//                    refined.getId());
        }
    }

    private void addNetworkSerialMenuItemActionPerformed(ActionEvent evt) {
        TestBedControllerList.newInstance().getNetworkSerialConfigController().operationNewConfig();
    }

    private void editNetworkSerialMenuItemActionPerformed(ActionEvent evt) {
        TbedMutableTreeNode node = TestBedControllerList.newInstance().getTbedTreeController().getSelectedTreeNode();
        TestBedControllerList.newInstance().getNetworkSerialConfigController().operationEditConfig(
                node);
        TestBedControllerList.newInstance().getTbedTreeController().operationRefreshTree();
    }

    private void deleteNetworkSerialMenuItemActionPerformed(ActionEvent evt) {
    }

    private void addSerialConnMenuItemActionPerformed(ActionEvent evt) {
        TestBedControllerList.newInstance().getSerialConfigController().operationNewSerialConfig();
    }

    private void editSerialConnMenuItemActionPerformed(ActionEvent evt) {
        TbedMutableTreeNode node = TestBedControllerList.newInstance().getTbedTreeController().getSelectedTreeNode();
        TestBedControllerList.newInstance().getSerialConfigController().operationEditSerialConfig(
                node);
        TestBedControllerList.newInstance().getTbedTreeController().operationRefreshTree();
    }

    private void deleteSerialConnMenuItemActionPerformed(ActionEvent evt) {
        TestBedItem tbedItem = TestBedControllerList.newInstance().getTbedTreeController().getSelectedTestBedItem();
        if (tbedItem != null && tbedItem instanceof SerialConnectionRefined) {
            SerialConnectionRefined refined = (SerialConnectionRefined) tbedItem;
            if (confirmDeleteDialog(refined)) {
                TestBedControllerList.newInstance().getSerialConfigController().operationDeleteSerialConn(
                        refined.getId());
            }
        }
    }

    private void addAdapterMenuItemActionPerformed(ActionEvent evt) {
        TestBedControllerList.newInstance().getNetworkAdapterController().operationNewAdapter();
    }

    private void editAdapterMenuItemActionPerformed(ActionEvent evt) {
        TbedMutableTreeNode node = TestBedControllerList.newInstance().getTbedTreeController().getSelectedTreeNode();
        TestBedControllerList.newInstance().getNetworkAdapterController().operationEditAdapter(
                node);
        TestBedControllerList.newInstance().getTbedTreeController().operationRefreshTree();
    }

    private void deleteAdapterMenuItemActionPerformed(ActionEvent evt) {
        TestBedControllerList.newInstance().getNetworkAdapterController().operationDeleteSelectedAdapter();
    }

    private void addDutMenuItemActionPerformed(ActionEvent evt) {
        TestBedControllerList.newInstance().getDutController().operationNewDut();
    }

    private void editDutMenuItemActionPerformed(ActionEvent evt) {
        TbedMutableTreeNode node = TestBedControllerList.newInstance().getTbedTreeController().getSelectedTreeNode();
        TestBedControllerList.newInstance().getDutController().operationEditDut(
                node);
        TestBedControllerList.newInstance().getTbedTreeController().operationRefreshTree();
    }

    private void deleteDutMenuItemActionPerformed(ActionEvent evt) {
        TestBedControllerList.newInstance().getDutController().operationDeleteSelectedDut();
    }

    private void addDeviceMenuItemActionPerformed(java.awt.event.ActionEvent evt) {
        m_deviceDefinitionController.operationNewDeviceDefinition();
    }

    private void editDeviceMenuItemActionPerformed(java.awt.event.ActionEvent evt) {
        m_deviceDefinitionController.operationEditSelectedDevice();
        m_treeController.operationRefreshTree();
    }

    private void deleteDeviceMenuItemActionPerformed(java.awt.event.ActionEvent evt) {
        m_deviceDefinitionController.operationDeleteSelectedDevice();
    }

    private void addFirmwareMenuItemActionPerformed(java.awt.event.ActionEvent evt) {
        m_firmwareController.operationNewFirmware();
    }

    private void editFirmwareMenuItemActionPerformed(java.awt.event.ActionEvent evt) {
        m_firmwareController.operationEditSelectedFirmware();
        m_treeController.operationRefreshTree();
    }

    private void deleteFirmwareMenuItemActionPerformed(java.awt.event.ActionEvent evt) {
        TestBedItem tbedItem = TestBedControllerList.newInstance().getTbedTreeController().getSelectedTestBedItem();
        if (tbedItem != null && tbedItem instanceof DeviceFirmwareRefined) {
            DeviceFirmwareRefined refined = (DeviceFirmwareRefined) tbedItem;
            if (confirmDeleteDialog(refined)) {
                TestBedControllerList.newInstance().getDeviceFirmwareController().operationDeleteFirmware(
                        refined);
            }
        }
    }

    private void addTestPcMenuItemActionPerformed(java.awt.event.ActionEvent evt) {
        TestBedControllerList.newInstance().getTestPcController().operationNewTestPc();
    }

    private void editTestPcMenuItemActionPerformed(java.awt.event.ActionEvent evt) {
        TbedMutableTreeNode node = TestBedControllerList.newInstance().getTbedTreeController().getSelectedTreeNode();
        TestBedControllerList.newInstance().getTestPcController().operationEditTestPc(
                node);
        TestBedControllerList.newInstance().getTbedTreeController().operationRefreshTree();
    }

    private void deleteTestPcMenuItemActionPerformed(java.awt.event.ActionEvent evt) {
        TestBedItem tbedItem = TestBedControllerList.newInstance().getTbedTreeController().getSelectedTestBedItem();
        if (tbedItem != null && tbedItem instanceof TestPcRefined) {
            TestPcRefined refined = (TestPcRefined) tbedItem;
            if (confirmDeleteDialog(refined)) {
                TestBedControllerList.newInstance().getTestPcController().operationRemoveTestPc(
                        refined.getId());
            }
        }
    }

    private void addDeviceGroupMenuItemActionPerformed(java.awt.event.ActionEvent evt) {
        TestBedControllerList.newInstance().getDeviceGroupController().operationNewDeviceGroup();
    }

    private void editDeviceGroupMenuItemActionPerformed(java.awt.event.ActionEvent evt) {
        TbedMutableTreeNode node = TestBedControllerList.newInstance().getTbedTreeController().getSelectedTreeNode();
        TestBedControllerList.newInstance().getDeviceGroupController().operationEditDeviceGroup(
                node);
        TestBedControllerList.newInstance().getTbedTreeController().operationRefreshTree();
    }

    private void deleteDeviceGroupMenuItemActionPerformed(java.awt.event.ActionEvent evt) {
        TestBedItem tbedItem = TestBedControllerList.newInstance().getTbedTreeController().getSelectedTestBedItem();
        if (tbedItem != null && tbedItem instanceof DeviceGroupRefined) {
            DeviceGroupRefined refined = (DeviceGroupRefined) tbedItem;
            TestBedControllerList.newInstance().getDeviceGroupController().operationRemoveDeviceGroup(
                    refined.getId());
        }
    }

    private void editDeviceGroupDetailMenuItemActionPerformed(ActionEvent evt) {
        TbedMutableTreeNode node = m_treeController.getSelectedTreeNode();
        m_deviceGroupDetailController.operationEditDeviceGroupDetail(node);
        m_treeController.operationRefreshTree();
    }

    private void addDeviceGroupDetailMenuItemActionPerformed(ActionEvent evt) {
        m_deviceGroupDetailController.operationNewDeviceGroupDetail();
    }

    private void deleteDeviceGroupDetailMenuItemActionPerformed(ActionEvent evt) {
        m_deviceGroupDetailController.operationDeleteSelectedDeviceGroupDetail();
    }

    private boolean confirmDeleteDialog(TestPcRefined refined) {
        if (refined == null) {
            return false;
        }
        boolean confirmForDelete = false;
        if (refined.numberOfDeviceGroupInclusions() > 0) {
            StringBuilder sb = new StringBuilder(
                    "TEST PC is used within these device groups:\n");
            List<String> strList = refined.getDeviceGroupInclusions();
            for (Iterator<String> it = strList.iterator(); it.hasNext();) {
                sb.append("      - " + it.next() + "\n");
            }
            sb.append("Remove TEST PC from listed device groups!");
            javax.swing.JOptionPane.showMessageDialog(null, sb.toString(),
                    "Delete Confirmation",
                    javax.swing.JOptionPane.ERROR_MESSAGE);
        } else {
            int result = javax.swing.JOptionPane.showConfirmDialog(null,
                    "Are you sure you want to delete this TEST PC?",
                    "Delete Confirmation",
                    javax.swing.JOptionPane.YES_NO_CANCEL_OPTION,
                    javax.swing.JOptionPane.QUESTION_MESSAGE);
            if (result == javax.swing.JOptionPane.YES_OPTION) {
                confirmForDelete = true;
            }
        }
        return confirmForDelete;
    }

    private boolean confirmDeleteDialog(DeviceFirmwareRefined refined) {
        if (refined == null) {
            return false;
        }
        boolean confirmForDelete = false;
        if (refined.numberOfDutInclusions() > 0) {
            StringBuilder sb = new StringBuilder(
                    "Fimware is used within these DUTs:\n");
            List<DutRefined> duts = refined.getDutInclusions();
            for (Iterator<DutRefined> it = duts.iterator(); it.hasNext();) {
                DutRefined dut = it.next();
                sb.append(
                        "      - " + dut.getName() + " at " + dut.getPc().getName() + "\n");
            }
            sb.append("Remove Fimware from listed DUTs!");
            javax.swing.JOptionPane.showMessageDialog(null, sb.toString(),
                    "Delete Confirmation",
                    javax.swing.JOptionPane.ERROR_MESSAGE);
        } else {
            int result = javax.swing.JOptionPane.showConfirmDialog(null,
                    "Are you sure you want to delete this Firmware?",
                    "Delete Confirmation",
                    javax.swing.JOptionPane.YES_NO_CANCEL_OPTION,
                    javax.swing.JOptionPane.QUESTION_MESSAGE);
            if (result == javax.swing.JOptionPane.YES_OPTION) {
                confirmForDelete = true;
            }
        }
        return confirmForDelete;
    }

    private boolean confirmDeleteDialog(SerialConnectionRefined refined) {
        if (refined == null) {
            return false;
        }
        boolean confirmForDelete = false;
        if (refined.numberOfDutInclusions() > 0) {
            StringBuilder sb = new StringBuilder(
                    "Serial Connetion is used within these DUTs:\n");
            List<DutRefined> duts = refined.getDutInclusions();
            for (Iterator<DutRefined> it = duts.iterator(); it.hasNext();) {
                DutRefined dut = it.next();
                sb.append(
                        "      - " + dut.getName() + " at " + dut.getPc().getName() + "\n");
            }
            sb.append("Remove Serial Connection from listed DUTs!");
            javax.swing.JOptionPane.showMessageDialog(null, sb.toString(),
                    "Delete Confirmation",
                    javax.swing.JOptionPane.ERROR_MESSAGE);
        } else {
            int result = javax.swing.JOptionPane.showConfirmDialog(null,
                    "Are you sure you want to delete this Serial Connection?",
                    "Delete Confirmation",
                    javax.swing.JOptionPane.YES_NO_CANCEL_OPTION,
                    javax.swing.JOptionPane.QUESTION_MESSAGE);
            if (result == javax.swing.JOptionPane.YES_OPTION) {
                confirmForDelete = true;
            }
        }
        return confirmForDelete;
    }
    // Variables declaration - do not modify
    private javax.swing.JMenuItem addDeviceGroupMenuItem;
    private javax.swing.JMenuItem addDeviceMenuItem;
    private javax.swing.JMenuItem addFirmwareMenuItem;
    private javax.swing.JMenuItem addTestPcMenuItem;
    private javax.swing.JMenuItem deleteDeviceGroupMenuItem;
    private javax.swing.JMenuItem deleteDeviceMenuItem;
    private javax.swing.JMenuItem deleteFirmwareMenuItem;
    private javax.swing.JMenuItem deleteTestPcMenuItem;
    private javax.swing.JMenuItem editDeviceGroupMenuItem;
    private javax.swing.JMenuItem editDeviceMenuItem;
    private javax.swing.JMenuItem editFirmwareMenuItem;
    private javax.swing.JMenuItem editTestPcMenuItem;
    private javax.swing.JMenuItem addDeviceGroupDetailMenuItem;
    private javax.swing.JMenuItem editDeviceGroupDetailMenuItem;
    private javax.swing.JMenuItem deleteDeviceGroupDetailMenuItem;
    private javax.swing.JMenuItem addDutMenuItem;
    private javax.swing.JMenuItem editDutMenuItem;
    private javax.swing.JMenuItem deleteDutMenuItem;
    private javax.swing.JMenuItem addAdapterMenuItem;
    private javax.swing.JMenuItem editAdapterMenuItem;
    private javax.swing.JMenuItem deleteAdapterMenuItem;
    private javax.swing.JMenuItem addSerialConnMenuItem;
    private javax.swing.JMenuItem editSerialConnMenuItem;
    private javax.swing.JMenuItem deleteSerialConnMenuItem;
    private javax.swing.JMenuItem addDirectSerialMenuItem;
    private javax.swing.JMenuItem editDirectSerialMenuItem;
    private javax.swing.JMenuItem deleteDirectSerialMenuItem;
    private javax.swing.JMenuItem addNetworkSerialMenuItem;
    private javax.swing.JMenuItem editNetworkSerialMenuItem;
    private javax.swing.JMenuItem deleteNetworkSerialMenuItem;
    private javax.swing.JPopupMenu popupMenu;
    // End of variables declaration
}
